package com.zlc.common.core.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlc.common.common.service.BaseServiceImpl;
import com.zlc.common.core.process.model.entity.StoneNodeApproveConfig;
import com.zlc.common.core.process.mapper.StoneNodeApproveConfigMapper;
import com.zlc.common.core.process.model.entity.StoneProcessNode;
import com.zlc.common.core.process.model.vo.StoneNodeApproveConfigVo;
import com.zlc.common.core.process.model.vo.StoneNodeApproveUserConfigVo;
import com.zlc.common.core.process.model.vo.StoneProcessNodeVo;
import com.zlc.common.core.process.service.StoneNodeApproveConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author  zl
 * @date 2023-10-17 
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class StoneNodeApproveConfigServiceImpl extends BaseServiceImpl<StoneNodeApproveConfigMapper, StoneNodeApproveConfig, StoneNodeApproveConfigVo> implements StoneNodeApproveConfigService{


    @Override
    public void removeByProcessId(String processId) {
        LambdaQueryWrapper<StoneNodeApproveConfig> wrapper = wrapper()
                .eq(StoneNodeApproveConfig::getProcessId, processId);
        List<StoneNodeApproveConfigVo> nodeVos = queryVoList(wrapper);
        if(!ObjectUtils.isEmpty(nodeVos)){
            List<String> ids = nodeVos.stream().map(StoneNodeApproveConfigVo::getId).collect(Collectors.toList());
            deleteObjByIds(ids);
        }
    }

    @Override
    public List<StoneNodeApproveConfigVo> getByProcessId(String processId) {
        LambdaQueryWrapper<StoneNodeApproveConfig> wrapper = wrapper()
                .eq(StoneNodeApproveConfig::getProcessId, processId);
        return queryVoList(wrapper);
    }

    @Override
    public StoneNodeApproveConfigVo getByNodeId(String processId, String nodeId) {
        LambdaQueryWrapper<StoneNodeApproveConfig> wrapper = wrapper()
                .eq(StoneNodeApproveConfig::getProcessId, processId)
                .eq(StoneNodeApproveConfig::getNodeId,nodeId);
        return queryOne(wrapper);
    }
}
